package com.bawei.monthdemo2207a.month01.view

import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bawei.monthdemo2207a.R

/**
 * 作者：赵亮
 * 时间：2024/12/26 12:03
 * 功能：协议页面
 */
@Composable
fun XieYiPage(navController: NavController = rememberNavController()) {

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(top = 24.dp)
    ) {
        // 标题
        Row(
            verticalAlignment = Alignment.CenterVertically,
            modifier = Modifier
                .fillMaxWidth()
                .height(50.dp)
                .background(color = colorResource(id = R.color.purple_200))
        ) {
            Icon(
                modifier = Modifier
                    .padding(start = 15.dp)
                    .clickable {
                        // 返回上一个页面
                        navController.popBackStack()
                    },
                imageVector = Icons.Default.ArrowBack,
                contentDescription = null
            )
            Text(modifier = Modifier.padding(start = 15.dp), text = "用户协议")
        }


        // 通过web View显示协议页面
        AndroidView(factory = {
            val webView = WebView(it)
            webView.loadUrl("http://www.baidu.com")
            webView.webViewClient = WebViewClient()
            webView
        })
    }
}

@Preview(showSystemUi = true)
@Composable
fun XieYiPagePreview() {
    XieYiPage()
}

